package edu.qc.cs370.project1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Deck {
	private ArrayList<Card> deck;
	private int numDecks;
	private int numCards;
	private Random rand = new Random();
	
	public Deck ()
	{
	}
	
	public Deck(int x)
	{
		numDecks = x;
		numCards = 52 * numDecks;
		rand = new Random();
		shuffle();
	}

	public void shuffle()
	{
		String CARD_SUITS[] = 
		{
			"Spades",
			"Hearts",
			"Diamonds",
			"Clubs"
		};
		
		String CARD_NAMES[] =
		{
			"Ace",
			"Two",
			"Three",
			"Four",
			"Five",
			"Six",
			"Seven",
			"Eight",
			"Nine",
			"Ten",
			"Jack",
			"Queen",
			"King"
		};
		
		String CARD_CHAR_SUIT[] =
		{
			"A",
			"2",
			"3",
			"4",
			"5",
			"6",
			"7",
			"8",
			"9",
			"T",
			"J",
			"Q",
			"K"
		};
		
		int CARD_VALUES[] =
		{
			1,
			2,
			3,
			4,
			5,
			6,
			7,
			8,
			9,
			10,
			10,
			10,
			10
		};
		
		//Create the deck
		deck = new ArrayList<Card>();
		for (int x = 0; x < numDecks; x++)
		{
			for (int y = 0; y < CARD_SUITS.length; y++)
			{
				for (int z = 0; z < CARD_NAMES.length; z++)
				{
					String name = CARD_NAMES[z] + " of " + CARD_SUITS[y];
					Card card = new Card(CARD_VALUES[z], CARD_CHAR_SUIT[z].charAt(0), name);
					deck.add(card);
				}
			}
		}
		
		
		//Shuffle deck
		Collections.shuffle(deck);
	}


	public Card getCard()
	{
		if (deck.size() == 0)
		{
			shuffle();
		}

		return deck.remove(0);
	}
	
}
